/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.adfm.managedbean.converter;

import java.io.Serializable;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.springframework.stereotype.Component;

@FacesConverter("genericConverter")
public class GenericConverter implements Converter, Serializable {
    
    private static Map <UUID, Object> temporaryStore = new WeakHashMap<>();
 
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return temporaryStore.get(UUID.fromString(value));
    }
 
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
    	UUID id = UUID.randomUUID();
        temporaryStore.put(id, value);
        return id.toString();
    }
    
}

